package com.xiaoshuidi.cloud.module.contract.service.bill;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xiaoshuidi.cloud.framework.common.pojo.PageParam;
import com.xiaoshuidi.cloud.framework.common.pojo.PageResult;
import com.xiaoshuidi.cloud.module.contract.controller.admin.bill.vo.OrderDetailVo;
import com.xiaoshuidi.cloud.module.contract.controller.admin.bill.vo.OrderDetaillAndOrderFeeVo;
import com.xiaoshuidi.cloud.module.contract.controller.admin.bill.vo.rentOrder.*;
import com.xiaoshuidi.cloud.module.contract.controller.admin.contract.vo.EnergyConsumptionImportExcelVO;
import com.xiaoshuidi.cloud.module.contract.controller.admin.contract.vo.HomeQueryVO;
import com.xiaoshuidi.cloud.module.contract.controller.admin.roommate.vo.ContractRoommateImportRespVO;
import com.xiaoshuidi.cloud.module.contract.controller.app.contract.vo.AppRentOrderCreateReq;
import com.xiaoshuidi.cloud.module.contract.dal.dataobject.bill.RentOrderDO;
import com.xiaoshuidi.cloud.module.contract.util.bill.RemainingAmount;
import com.xiaoshuidi.cloud.module.contract.vo.ApproveReqVO;
import com.xiaoshuidi.cloud.module.contract.vo.GetSowTicketOrderByIdsReq;
import com.xiaoshuidi.cloud.module.contract.vo.RentOrderSowTicketVO;

import java.time.LocalDate;
import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * 账单 Service 接口
 *
 * @author 合房租赁
 */
public interface RentOrderService {

    /**
     * 批量创建合同账单
     *
     * @param billsList 创建信息
     *
     * @return 编号
     */
    List<RentOrderDO> createBatchRentOrder( List<OrderDetailVo> billsList ,RentOrderVO rentOrder);

    String nextRentOrderNo();

    /**
    * 获取应退账单-根据合同id
    * @param contractId 合同id
    * */
    List<RemainingAmount>  getByContractId(Long contractId );

    /**
     * 更新账单 账单id
     *
     * @param updateReqVO 更新信息
     */
    void updateContractRentOrder( RentOrderUpdateReqVO updateReqVO);

    void updateContractRentOrderById(RentOrderUpdateReqVO updateObj);

    /**
     * 删除账单 账单id
     *
     * @param id 编号
     */
    void deleteContractRentOrder(Long id);

    /**
     * 单个获得账单 账单id
     *
     * @param id 编号
     * @return 账单
     */
    RentOrderDO getContractRentOrder(Long id);

    /**
     * 获得账单列表
     *
     * @param ids 编号
     * @return 账单列表
     */
    List<RentOrderDO> getContractRentOrderList(Collection<Long> ids);

    /**
     * 根据合同id获取各类账单信息
     * @param contractId 合同id
     * @param orderTypes 账单类型
     */
    RentOrderInfoVO getRentOrder(Long contractId, List<String> orderTypes);

    /**
     * 获取应收账单
     */
    RentOrderHomeRespVO getReceivableOrders(HomeQueryVO req);

    /**
     * 创建杂费账单及明细
     */
    List<RentOrderDO> createRentOrder(RentOrderCreateReq orderFeesCreateVO);

    List<RentOrderDO> createRentOrder(RentOrderCreateReq req, Boolean flag);


    /*
     * 获取租客账单列表分页
     * */
    Page<RentOrderResp> getRentOrder(RentOrderQueryVo rentOrderQueryVo);


    /*
     * 获取租客账单列表分页
     * */
    PageResult<RentOrderResp> getRentOrderPage(RentOrderQueryVo rentOrderQueryVo);

    /*
     * 获取合同账单
     * */
    List<RentOrderRespVO> getOrderByContractId(Long id);

    /**
     * 获取合同账单
     *
     * @param contractId 合同id
     */
    List<RentOrderDO> getRentOrderByContractId(Long contractId);

    /**
     * 根据业务ID删除账单及账单明细
     * @param businessId 业务ID (合同id)
     * @param orderType 订单类型
     */
    void deleteOrderByBusinessId(Long businessId, String orderType);

    /**
    * 查询租客账单
    * */
    List<OrderDetaillAndOrderFeeVo> getOrder(Long loginUserId,String payStatus);

    /**
     * 合同账单统计
     * @param contractId 合同id
     */
    RentOrderCountVO getContractOrderCount(Long contractId);

    /**
    * 退租前是否存在 未付款账单
    * */
    void unpaidOrder(LocalDate evictionTime,List<Long> contractIds,List<String> orderType);

    String orderCollection(List<Long> ids);

    String orderReminder(List<RentOrderDO> rentOrderDOList);

    /**
     * 首期账单支付判断
     * @param contractId
     * @return: java.lang.Boolean
     * true 已支付
     * false 未支付
     */
    Boolean getFirstOrderPayStatus(Long contractId);

    /**
     * 企业合同账单 待处理、未出账、已处理
     * @param companyContractId 企业合同编号
     * @return: com.xiaoshuidi.cloud.module.contract.controller.admin.bill.vo.rentOrder.RentOrderInfoVO
     */
    RentOrderInfoVO getCompanyOrders(Long companyContractId);

    /**
     * 企业子账单id获取企业账单批次号
     * @param ids
     * @return: java.lang.String
     */
    String getCompanyBatchNo(List<Long> ids);

    /**
     * 根据企业账单批次号获取账单列表
     * @param companyBatchNo
     * @return: java.util.List<com.xiaoshuidi.cloud.module.contract.dal.dataobject.bill.RentOrderDO>
     */
    List<RentOrderDO> getRentListByBatchNo(String companyBatchNo);

    /**
     * 企业催款
     * @param reqVO
     * @return: java.lang.String
     */
    String urgeCompanyPayOrder(CompanyOrderUrgeReqVO reqVO);

    List<OrderDetaillAndOrderFeeVo> getInvoiceOrder(Long loginUserId, Integer invoiceStatus);

    /**
    * 查询合同未支付的账单
    * */
    List<RentOrderDO> getRentOrderByBusinessId(Long contractId);

    /**
     * 根据房间id获取各类账单信息
     * @param roomId 房间id
     * @param orderTypes 账单类型
     */
    RentOrderInfoVO getRentOrderByRoomId(Long roomId, List<String> orderTypes);

    /**
     * 创建杂费账单及明细
     */
    void createAppRentOrder(AppRentOrderCreateReq req);

    /**
    * 逾期未支付的账单
    * */
     List<RentOrderDO> overdueUnpaidOrder(List<Long> contractIds) ;

    void orderApproval(ApproveReqVO reqVO);

    List<RentOrderContractVO> getContractOrder(Long id);

    void updateById(RentOrderDO update);

    PageResult<RentOrderDO> getReminderOrder(PageParam page);

    List<RentOrderExcelVO> exportOrder(RentOrderQueryVo req);

    List<RentOrderSowTicketVO> getOrderBySowTicket(Long id);

    RentOrderDetailVO getOrderDetail(Long id);

    int update(Wrapper<RentOrderDO> updateWrapper);

    void updateBatch(List<RentOrderDO> list);

    /**
     * 逾期账单处理  恢复水电
     * @param rentOrderDO
     * @return: void
     */
    void overdueOrderDeal(RentOrderDO rentOrderDO);

    Map<Long, List<RentOrderSowTicketVO>> getSowTicketOrderByIds(GetSowTicketOrderByIdsReq getSowTicketOrderByIdsReq);
    ContractRoommateImportRespVO energyConsumptionImport(List<EnergyConsumptionImportExcelVO> list);
    JSONObject templateDownload(Long apartmentId);
    List<RentOrderDO> getPaymentRentOrderList(String startTime, String endTime);
}
